package com.cc.data_explore.gui.tab.rule;

import de.saxsys.mvvmfx.ViewModel;
import javafx.beans.property.MapProperty;
import javafx.beans.property.SimpleMapProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import org.dromara.hutool.core.collection.CollUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * NewMappingFieldView
 *
 * @author aa
 * @version 1.0
 * @since 2025/4/10
 */
public class NewConcatViewModel implements ViewModel {

    public final StringProperty newName = new SimpleStringProperty();
    public final List<Map<String, String>> sourceField = new ArrayList<>();
    public final StringProperty content = new SimpleStringProperty();
    public final StringProperty preview = new SimpleStringProperty();
    public final StringProperty sheetName = new SimpleStringProperty();
    private final ObservableMap<String, String> previewData = FXCollections.observableHashMap();
    public static final String SOURCE_FIELD_CHANGE = "source_field_change";

    public void initData(ObservableMap<String, String> columnMap, String sheetName, Map<String, String> previewData) {
        this.sheetName.set(sheetName);
        columnMap.forEach((k, v) -> sourceField.add(Map.of(k, v)));
        if (CollUtil.isNotEmpty(previewData)) {
            this.previewData.putAll(previewData);
        }
        publish(SOURCE_FIELD_CHANGE);
    }

    public boolean save() {
        return true;
    }

    public String getNewName() {
        return newName.get();
    }

    public StringProperty newNameProperty() {
        return newName;
    }

    public List<Map<String, String>> getSourceField() {
        return sourceField;
    }

    public String getContent() {
        return content.get();
    }

    public StringProperty contentProperty() {
        return content;
    }

    public String getPreview() {
        return preview.get();
    }

    public StringProperty previewProperty() {
        return preview;
    }

    public StringProperty sheetNameProperty() {
        return sheetName;
    }

    public ObservableMap<String, String> getPreviewData() {
        return previewData;
    }

    public ObservableMap<String, String> previewDataProperty() {
        return previewData;
    }
}
